package com.tianluo.tianluobookstore.config;

import com.tianluo.tianluobookstore.filter.JwtInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private JwtInterceptor jwtInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册拦截器，但排除登录和注册接口
        registry.addInterceptor(jwtInterceptor)
                .addPathPatterns("/**") // 匹配所有路径
                .excludePathPatterns("/user/login", "/registerUser","/index"
                        ,"/alipay/createOrder","/alipay/return","/loginPage","/home"
                        ,"/addBook","/images/**","/static/**","/*.html","/alipay/notify"); // 排除登录和注册接口
    }
}
